import { GET_LIST_DATA, CHANGE_CURRENT_INDEX,ADD_SELECT_ITEM, REMOVE_SELECT_ITEM,CHANGE_ISSHOW_CHOOSE,CLEAN_CAR  } from './actionTypes.js';
// import api from "../../../http/api";
import axios from 'axios';

const getData = (obj) => {
    return {
        type: GET_LIST_DATA,
        obj: obj
    }
}

// 获取菜单数据
export const getLeftMenuData = () => (dispatch) => {
    // 默认显示全部的
    axios({
        method: 'get',
        url: './json/food.json'
    }).then((res) => {
        dispatch(getData({
            data: res.data.data, // 存入数据
        }))
    })

    // api.getMenuList({}).then((res) => {
    //
    // })
}

// 改变左侧选中的index
export const changeLeftIndex = (obj) => {
    return {
        type: CHANGE_CURRENT_INDEX,
        obj: obj
    }
}

// 增加菜品
export const addSelect = (obj) => {
    return {
        type:ADD_SELECT_ITEM,
        obj
    }
}

// 菜品减一
export const removeSelect = (obj) => {
    return {
        type:REMOVE_SELECT_ITEM,
        obj
    }
}

// 是否展示购物车列表
export const changeIsShowChoose = (obj) => {
    return {
        type:CHANGE_ISSHOW_CHOOSE,
        obj
    }
}

// 清空购物车
export const cleanCar = () => {
    return {
        type:CLEAN_CAR
    }
}

